"""
测试用例：
1. 打开百度页面
2. 输入his医疗
3. 点击搜索按钮
4. 点击出现的第一个链接
5. 点击免费试用
"""
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
services = Service('chromedriver.exe')
driver = webdriver.Chrome(service=services)

# 1. 打开百度页面
driver.get("https://www.baidu.com")
driver.implicitly_wait(15)
driver.maximize_window() # 全屏，最大化

# 2. 输入his医疗
driver.find_element(By.ID,"kw").send_keys("his医疗")

# 3. 点击搜索按钮
driver.find_element(By.ID,'su').click()

# 4. 点击出现的第一个链接
driver.find_element(By.XPATH,"//*[@id='3001']/div/div[1]/div/div/h3/div/a").click()

# 5. 点击免费试用
# 切换句柄
# 获取全部的句柄
win = driver.window_handles
# 跳进对应的句柄号
driver.switch_to.window(win[-1])
# driver.find_elements(By.CLASS_NAME,"ex-button")[0].click()
driver.find_element(By.XPATH,"//*[@id='app']/div[2]/div/div[2]").click()

# 6. 断言是否通过
text = driver.find_element(By.XPATH,"//*[@id='app']/div[5]/div[2]/div[3]/p[1]").text
assert text == "免费试用申请"
time.sleep(5)
